package cn.edu.scau.cmi.ema.dao;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.Session;


import cn.edu.scau.cmi.ema.domain.*;
import cn.edu.scau.cmi.ema.domain.base.CmiPagination;


import cn.edu.scau.cmi.ema.util.CmiSqlUtil;

@Repository("Event9ldDAO")
@Transactional
public class Event9ldDAOImpl extends AbstractJpaDao<Event9ld> implements Event9ldDAO {

	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(
			Arrays.asList(new Class<?>[] { Event9ld.class }));

	@PersistenceContext(unitName = "ema")
	private EntityManager entityManager;

	public Event9ldDAOImpl() {
		super();
	}

	public EntityManager getEntityManager() {
		return entityManager;
	}

	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	@Transactional
	public Event9ld findEvent9ldById(Integer id) throws DataAccessException {

		return findEvent9ldById(id, -1, -1);
	}

	@Transactional
	public Event9ld findEvent9ldById(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findEvent9ldById", startResult, maxRows, id);
			return (Event9ld) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByNumber(String number) throws DataAccessException {

		return findEvent9ldByNumber(number, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByNumber(String number, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByNumber", startResult, maxRows, number);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByNumberContaining(String number) throws DataAccessException {

		return findEvent9ldByNumberContaining(number, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByNumberContaining(String number, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByNumberContaining", startResult, maxRows, number);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByEffect(String effect) throws DataAccessException {

		return findEvent9ldByEffect(effect, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByEffect(String effect, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByEffect", startResult, maxRows, effect);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByEffectContaining(String effect) throws DataAccessException {

		return findEvent9ldByEffectContaining(effect, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByEffectContaining(String effect, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByEffectContaining", startResult, maxRows, effect);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByDiscoverytime(String discoverytime) throws DataAccessException {

		return findEvent9ldByDiscoverytime(discoverytime, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByDiscoverytime(String discoverytime, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByDiscoverytime", startResult, maxRows, discoverytime);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByDiscoverytimeContaining(String discoverytime) throws DataAccessException {

		return findEvent9ldByDiscoverytimeContaining(discoverytime, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByDiscoverytimeContaining(String discoverytime, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByDiscoverytimeContaining", startResult, maxRows, discoverytime);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByUrl(String url) throws DataAccessException {

		return findEvent9ldByUrl(url, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByUrl(String url, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByUrl", startResult, maxRows, url);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByUrlContaining(String url) throws DataAccessException {

		return findEvent9ldByUrlContaining(url, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByUrlContaining(String url, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByUrlContaining", startResult, maxRows, url);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByDiscoveraddress(String discoveraddress) throws DataAccessException {

		return findEvent9ldByDiscoveraddress(discoveraddress, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByDiscoveraddress(String discoveraddress, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByDiscoveraddress", startResult, maxRows, discoveraddress);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByDiscoveraddressContaining(String discoveraddress) throws DataAccessException {

		return findEvent9ldByDiscoveraddressContaining(discoveraddress, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByDiscoveraddressContaining(String discoveraddress, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByDiscoveraddressContaining", startResult, maxRows,
				discoveraddress);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByName(String name) throws DataAccessException {

		return findEvent9ldByName(name, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByName(String name, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByName", startResult, maxRows, name);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByNameContaining(String name) throws DataAccessException {

		return findEvent9ldByNameContaining(name, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByNameContaining(String name, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByNameContaining", startResult, maxRows, name);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByDescription(String description) throws DataAccessException {

		return findEvent9ldByDescription(description, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByDescription(String description, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByDescription", startResult, maxRows, description);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByDescriptionContaining(String description) throws DataAccessException {

		return findEvent9ldByDescriptionContaining(description, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByDescriptionContaining(String description, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByDescriptionContaining", startResult, maxRows, description);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByFood(String food) throws DataAccessException {

		return findEvent9ldByFood(food, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByFood(String food, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByFood", startResult, maxRows, food);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByFoodContaining(String food) throws DataAccessException {

		return findEvent9ldByFoodContaining(food, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByFoodContaining(String food, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByFoodContaining", startResult, maxRows, food);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByProducer(String producer) throws DataAccessException {

		return findEvent9ldByProducer(producer, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByProducer(String producer, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByProducer", startResult, maxRows, producer);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByProducerContaining(String producer) throws DataAccessException {

		return findEvent9ldByProducerContaining(producer, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByProducerContaining(String producer, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByProducerContaining", startResult, maxRows, producer);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByAdultertype(String adultertype) throws DataAccessException {

		return findEvent9ldByAdultertype(adultertype, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByAdultertype(String adultertype, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByAdultertype", startResult, maxRows, adultertype);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByAdultertypeContaining(String adultertype) throws DataAccessException {

		return findEvent9ldByAdultertypeContaining(adultertype, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByAdultertypeContaining(String adultertype, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByAdultertypeContaining", startResult, maxRows, adultertype);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByFoodbatchfiller(String foodbatchfiller) throws DataAccessException {

		return findEvent9ldByFoodbatchfiller(foodbatchfiller, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByFoodbatchfiller(String foodbatchfiller, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByFoodbatchfiller", startResult, maxRows, foodbatchfiller);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByFoodbatchfillerContaining(String foodbatchfiller) throws DataAccessException {

		return findEvent9ldByFoodbatchfillerContaining(foodbatchfiller, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByFoodbatchfillerContaining(String foodbatchfiller, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByFoodbatchfillerContaining", startResult, maxRows,
				foodbatchfiller);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldBySourceaddress(String sourceaddress) throws DataAccessException {

		return findEvent9ldBySourceaddress(sourceaddress, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldBySourceaddress(String sourceaddress, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldBySourceaddress", startResult, maxRows, sourceaddress);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldBySourceaddressContaining(String sourceaddress) throws DataAccessException {

		return findEvent9ldBySourceaddressContaining(sourceaddress, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldBySourceaddressContaining(String sourceaddress, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldBySourceaddressContaining", startResult, maxRows, sourceaddress);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByFoodtype(String foodtype) throws DataAccessException {

		return findEvent9ldByFoodtype(foodtype, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByFoodtype(String foodtype, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByFoodtype", startResult, maxRows, foodtype);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByFoodtypeContaining(String foodtype) throws DataAccessException {

		return findEvent9ldByFoodtypeContaining(foodtype, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByFoodtypeContaining(String foodtype, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByFoodtypeContaining", startResult, maxRows, foodtype);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByHazard(String hazard) throws DataAccessException {

		return findEvent9ldByHazard(hazard, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByHazard(String hazard, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByHazard", startResult, maxRows, hazard);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByHazardContaining(String hazard) throws DataAccessException {

		return findEvent9ldByHazardContaining(hazard, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByHazardContaining(String hazard, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByHazardContaining", startResult, maxRows, hazard);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByAdulterlink(String adulterlink) throws DataAccessException {

		return findEvent9ldByAdulterlink(adulterlink, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByAdulterlink(String adulterlink, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByAdulterlink", startResult, maxRows, adulterlink);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByAdulterlinkContaining(String adulterlink) throws DataAccessException {

		return findEvent9ldByAdulterlinkContaining(adulterlink, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByAdulterlinkContaining(String adulterlink, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByAdulterlinkContaining", startResult, maxRows, adulterlink);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldBySource(String source) throws DataAccessException {

		return findEvent9ldBySource(source, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldBySource(String source, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldBySource", startResult, maxRows, source);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldBySourceContaining(String source) throws DataAccessException {

		return findEvent9ldBySourceContaining(source, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldBySourceContaining(String source, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldBySourceContaining", startResult, maxRows, source);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByImported(Boolean imported) throws DataAccessException {

		return findEvent9ldByImported(imported, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByImported(Boolean imported, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByImported", startResult, maxRows, imported);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldByIslocked(Boolean islocked) throws DataAccessException {

		return findEvent9ldByIslocked(islocked, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByIslocked(Boolean islocked, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9ldByIslocked", startResult, maxRows, islocked);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@Transactional
	public Event9ld findEvent9ldByPrimaryKey(Integer id) throws DataAccessException {
		return findEvent9ldByPrimaryKey(id, -1, -1);
	}

	@Transactional
	public Event9ld findEvent9ldByPrimaryKey(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findEvent9ldByPrimaryKey", startResult, maxRows, id);
			return (Event9ld) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	@Transactional
	public Set<Event9ld> findEvent9ldsByIds(Set<Integer> ids) throws DataAccessException {
		try {
			Query query = createNamedQuery("findEvent9ldsByIds", -1, -1, ids);
			return new HashSet(query.getResultList());
		} catch (NoResultException nre) {
			return null;
		}
	}

	@Transactional
	public Set<Event9ld> findAllEvent9lds() throws DataAccessException {

		return findAllEvent9lds(-1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findAllEvent9lds(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllEvent9lds", startResult, maxRows);
		return new LinkedHashSet<Event9ld>(query.getResultList());
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9ld> findEvent9ldByCompositeProperities(String sql, int startResult, int maxRows) {
		return new LinkedHashSet<Event9ld>(createQuery(sql, startResult, maxRows).getResultList());
	}

	@Transactional
	public Set<Event9ld> findEvent9ldsByDetachedCriteria(CmiPagination page) throws DataAccessException {
		DetachedCriteria detachedCriteria = CmiSqlUtil.createDetachedCriteria(page, Event9ld.class);
		Session session = entityManager.unwrap(Session.class);
		Set<Event9ld> event9lds = new HashSet(detachedCriteria.getExecutableCriteria(session)
				.setFirstResult(page.getSearchBeginCursor()).setMaxResults(page.getPaginationSize()).list());

		return event9lds;
	}

	@Transactional
	public Event9ld findEvent9ldByPhysicalPrimaryKey(String number) throws DataAccessException {
		return findEvent9ldByPhysicalPrimaryKey(number, -1, -1);
	}

	@Transactional
	public Event9ld findEvent9ldByPhysicalPrimaryKey(String number, int startResult, int maxRows)
			throws DataAccessException {
		try {
			Query query = createNamedQuery("findEvent9ldByPhyscialPrimaryKey", startResult, maxRows, number);
			return (Event9ld) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	public boolean canBeMerged(Event9ld entity) {
		return true;
	}
}
